/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.bsplus.util.security;

import java.util.Arrays;
import java.util.Collection;
import org.bsplus.domain.User;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 *
 * @author sam
 */
public class UserDetailsImpl implements UserDetails
{    
    private User user;

    private GrantedAuthority grantedAuthority;

    public UserDetailsImpl(User user)
    {
        this.user = user;
        grantedAuthority = new GrantedAuthorityImpl(user.getRole());
    }

    @Override
    public Collection<GrantedAuthority> getAuthorities()
    {
        return Arrays.asList(grantedAuthority);
    }
    
    @Override
    public String getPassword()
    {
        return getUser().getPassword();
    }

    @Override
    public String getUsername()
    {
        return getUser().getUsername();
    }

    @Override
    public boolean isAccountNonExpired()
    {
        return true;
    }

    @Override
    public boolean isAccountNonLocked()
    {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired()
    {
        return true;
    }

    @Override
    public boolean isEnabled()
    {
        return true;
    }

    /**
     * @return the user
     */
    public User getUser()
    {
        return user;
    }
}
